package com.manage.auth;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import org.apache.log4j.Logger;
import com.common.util.Tools;
import com.model.auth.SResources;
import com.model.auth.User;
import com.opensymphony.xwork2.ActionSupport;
import com.service.auth.IResService;
import com.service.auth.IUserService;

/**
 * 用户登陆
 * 
 * @author zzx
 * 
 */
public class LoginAction extends ActionSupport {

	private static final Logger log = Logger.getLogger(LoginAction.class);
	private static final long serialVersionUID = 1L;

	@Resource
	private IUserService userService;
	@Resource
	private IResService resService;

	private List<SResources> menuList;
	private Set<String> menuSet; 
	private String treeHtml;
	
	
	/**
	 * 左侧菜单
	 * @return
	 */
	public String left(){
		try{
			treeHtml = "";
			User user = Tools.getCurrentUser();
			menuList = resService.getLeftMenus();
			List<String> userMenuList = userService.getUserRolesResId(user.getId());
			for(int i=0;i<menuList.size();i++){
				SResources one = menuList.get(i);
				if(one!=null){
					if(userMenuList.contains((one.getId()+""))){
						treeHtml = treeHtml +"<li><a href=\"#\" class=\"nav-top-item\">"+one.getName()+"</a>";
						List<SResources> childs = one.getChilds();
						if(childs!=null && !childs.isEmpty()){
							treeHtml = treeHtml +"<ul>";
							for(int c=0;c<childs.size();c++){
								SResources two = childs.get(c);
								treeHtml = treeHtml +"<li>";
								if(userMenuList.contains((two.getId()+""))){
									treeHtml = treeHtml +"<a href=\"javascript:void(0);\" onclick=\"go('"+Tools.getRequest().getContextPath()+two.getUrl()+"')\">"+two.getName()+"</a>";
								}
								treeHtml = treeHtml +"</li>";
							}
							treeHtml = treeHtml +"</ul>";
						}
						treeHtml = treeHtml +"</li>";
					}
				}
		      
			}
		}catch(Exception e){
			log.error("右侧菜单栏目", e);
		}
		return "left";
	}

	/**
	 * 右侧信息
	 * @return
	 */
	public  String right(){
		
		
		return "right";
	}
	
	
	public String manage(){
		
		return "main";
	}
	
	
	public String getTreeHtml() {
		return treeHtml;
	}

	public void setTreeHtml(String treeHtml) {
		this.treeHtml = treeHtml;
	}
	
	public List<SResources> getMenuList() {
		return menuList;
	}

	public void setMenuList(List<SResources> menuList) {
		this.menuList = menuList;
	}

	public Set<String> getMenuSet() {
		return menuSet;
	}

	public void setMenuSet(Set<String> menuSet) {
		this.menuSet = menuSet;
	}

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	public IResService getResService() {
		return resService;
	}

	public void setResService(IResService resService) {
		this.resService = resService;
	}

}
